package com.xinzhi.controller;

import com.alipay.api.AlipayApiException;
import com.xinzhi.pojo.Buy;
import com.xinzhi.service.PayService;
import com.xinzhi.utlis.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Random;

/* 订单接口 */
@RestController
public class OrderController {
    @Resource
    private PayService payService;//调用支付服务

    /*阿里支付*/
    @PostMapping("/alipay")
    public String alipay(String out_trade_no, String subject, String total_amount, String body) throws AlipayApiException {
        Buy buy = new Buy();
        //备注
        buy.setBody(body);
        //订单编号
        buy.setOut_trade_no(out_trade_no);
        //订单金额
        buy.setTotal_amount(new StringBuffer().append(total_amount));
        //订单名称
        buy.setSubject(subject);
        return payService.Buy(buy);
    }
    @GetMapping("/success")
    public Result returnAlipay(){
        return Result.ok("支付成功");
    }
    @GetMapping("/yibu")
    public Result notifyAlipay(){
        return Result.ok("支付宝");
    }
}
